﻿using System.IO;

namespace MusicFluent.Models;

public class SettingModel
{
    public string Cookie { get; init; } = "";
}

public static class CookieStatic
{
    public static void Save(this SettingModel model)
    {
        File.WriteAllText("cookie.json", System.Text.Json.JsonSerializer.Serialize(model));
    }

    public static SettingModel? Read()
    {
        if (!File.Exists("cookie.json"))
        {
            var model = new SettingModel();
            model.Save();
            return model;
        }

        var jsonContext = File.ReadAllText("cookie.json");
        return System.Text.Json.JsonSerializer.Deserialize<SettingModel>(jsonContext);
    }
}